package Domestic;
class DynamicStack implements InStack {
	public int stack[];
	private int tos;
	
	DynamicStack(int size){
		stack = new int[size];
		tos = -1;
	}
	
	public void push(int item){
		if(tos == stack.length-1){
			//increase the Stack size
			int temp[] = new int[stack.length * 2];
			System.out.println(stack.length);
			for (int i=0; i<stack.length; i++)
				temp[i] = stack[i];
			stack = temp;
			stack[++tos] = item;
		}
		else
			stack[++tos] = item;
	}
	public int pop(){
		if(tos<0){
			System.out.println("Stack underflow");
			return 0;
		}
		else
			return stack[tos--];
	}
}

public class StackInterface1 {
	public static void main(String[] args){
		DynamicStack myStack1 = new DynamicStack(5);
		DynamicStack myStack2 = new DynamicStack(8);
		
		for(int i = 1; i<=12;i++)
			myStack1.push(i);
		for (int i=0;i<20;i++)
			System.out.print(myStack1.stack[i] + " ");
		for(int i = 1; i<=20;i++)
			myStack2.push(i);
		for (int i=0;i<32;i++)
			System.out.print(myStack2.stack[i] + " ");
		
		System.out.println("\nStack in myStack1 Object");
		for (int i=1;i<=12;i++)
			System.out.println(myStack1.pop());
		
		System.out.println("Stack in myStack2 Object");
		for (int i=1;i<=20;i++)
			System.out.println(myStack2.pop());
	}

}
